<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <script src="js/jquery-3.5.1.js"></script>
    <script type="text/javascript">
        function toTest(){
           var username = $("#username").val();
           var password = $("#password").val();

            $.ajax({
                url:"test",
                type:"post",
                data:JSON.stringify({
                    username:username,
                    password:password
                }),
                contentType: "application/json;charset=UTF-8",
                dataType:"json",
                success:(data)=>{
                    if(data!=null){
                        alert("你输入的用户名是："+data.username+",密码是："+data.password);
                    }
                }
            })
        }
    </script>
</head>


<body>
<h1>INDEX.JSP</h1>
    <form>
        用户名：<input type="text" name="username" id="username"/>
        密码：<input type="password" name="password" id="password"/>
        <input type="button" value="测试" onclick="toTest()"/>
    </form>

</body>
</html>
